<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>日志管理</title>
<link href="../css/bootstrap.css" rel="stylesheet">
<!-- 引入jQuery核心js文件 -->
<script src="../js/jquery-3.2.1.min.js"></script>
<!-- 引入BootStrap核心js文件 -->
<script src="../js/bootstrap.min.js"></script>


<link rel="stylesheet" type="text/css" href="../css/simditor.css" />
<script type="text/javascript" src="../js/module.min.js"></script>
<script type="text/javascript" src="../js/hotkeys.min.js"></script>
<script type="text/javascript" src="../js/uploader.min.js"></script>
<script type="text/javascript" src="../js/simditor.min.js"></script>

<link rel="stylesheet" type="text/css" href="../css/front/compile.css" />
<link rel="stylesheet" type="text/css" href="../css/front/rizhigl.css" />

<script type="text/javascript">
	$(function() {
		$('#myTab a:last').tab('show'); //初始化显示哪个tab  
		$('#myTab a').click(function(e) {
			e.preventDefault(); //阻止a链接的跳转行为  
			$(this).tab('show'); //显示当前选中的链接及关联的content  
		});
		$("#hhh").click(function() {
			window.location.href = "updatebiaoqian";
		})

	});
	function sub(id) {
		var value = $("#" + id).val();
		$("#statement").val(value);
	}

	function artFrom() {
		var title = $("#title").val();
		if (title == "" || title == null) {
			var label = $("#titleLabel");
			label.text("文章标题不能为空！");
			return false;
		}
		var editor = $("#editor").val();
		if (editor == "" || editor == null) {
			var label = $("#editorLabel");
			label.text("文章内容不能为空！");
			return false;
		}

	}

	function chaxun() {

		// 获取取车的值
		var text = $("#text").val();
		var artId = $("#artId").val();
		$
				.ajax({
					type : "get",
					url : "chaxun",

					/* data : "text=" + text,  */
					data : "text=" + text + "&artId=" + artId,
					success : function(e) {
						// 获取传过来的数组
						var array = new Array();
						
						array = e.split(";");
						// 获取ul对象
						var table = $("#table");
						table.empty();
						for (var i = 0; i < array.length; i++) {

							// 创建子元素
							var tr = $("<tr>");
							var str = array[i];

							var s = str.split(",");
							for (var j = 0; j < s.length; j++) {
								var td = $("<td>");
								td.text(s[j]);
								td.css("width", "18%");
								tr.append(td);
							}
							var td1 = $("<td>");
							var input1 = $("<input />")
							input1.attr("type", "button");
							input1.val("删除");
							input1
									.addClass("btn btn-default del-a btn btn-danger shanchuart");
							td1.append(input1);

							var td2 = $("<td>");
							var input2 = $("<input />")
							input2.attr("type", "button");
							input2.val("修改");
							input2
									.addClass("btn btn-default del-a btn btn-danger xiugaiart");
							td1.append(input2);

							tr.append(td1);
							tr.addClass("myarticle");
							table.append(tr);

						}
					}
				});
		window.location = window.location;
	}
	$(function() {
		$(".add").on(
				"click",
				".xiugaiart",
				function() {
					var id = $(this).parents("tr").find("td").eq(0).text();
					var title = $(this).parents("tr").find("td").eq(1).text();
					var cla = $(this).parents("tr").find("td").eq(2).text();
					var time = $(this).parents("tr").find("td").eq(3).text();
					$("#artId").val(id);
					$("#xgartId").val(id);
					$("#xgartTitle").val(title);
					$("#xfartclassId").find("option[text=" + cla + "]").attr(
							"selected", true);
					$("#xgartTime").val(time);
					$("#myModal").modal("toggle");
				})
		$(".add").on("click", ".shanchuart", function() {
			var id = $(this).parents("tr").find("td").eq(0).text();
			$("#artId").val(id);
			$(this).on("click", ".myarticle", chaxun());

		})

	})

	$(function() {
		$(".add1").on(
				"click",
				".xiugaicaogao",
				function() {
					var id = $(this).parents("tr").find("td").eq(0).text();
					var title = $(this).parents("tr").find("td").eq(1).text();
					var cla = $(this).parents("tr").find("td").eq(2).text();
					var time = $(this).parents("tr").find("td").eq(3).text();
					$("#caogaoartId").val(id);
					$("#caogaoxgartId").val(id);
					$("#caogaoxgartTitle").val(title);
					$("#caogaoxfartclassId").find("option[text=" + cla + "]")
							.attr("selected", true);
					$("#caogaoxgartTime").val(time);
					$("#myModal1").modal("toggle");
				})
		$(".add1").on("click", ".shanchucaogao", function() {
			var id = $(this).parents("tr").find("td").eq(0).text();
			$("#caogaoartId").val(id);
			$("#caogaostate").val('1');
			$(this).on("click", ".myarticle2", caogaoshanchu());

		})
		$(".add1").on("click", ".fabiaocaogao", function() {
			var id = $(this).parents("tr").find("td").eq(0).text();
			$("#caogaoartId").val(id);
			$("#caogaostate").val('2');
			$(this).on("click", ".myarticle2", caogaoshanchu());

		})

	})
	function caogaoshanchu() {

		var caogaoartId = $("#caogaoartId").val();
		var sta = $("#caogaostate").val();
		 $
				.ajax({
					type : "get",
					url : "caogao",

					data : "caogaoartId=" + caogaoartId + "&state=" + sta,
					
					success : function(e) {
						// 获取传过来的数组
						var array = new Array();
						array = e.split(";");
						// 获取ul对象
						var table = $("#caogaotable");
						table.empty();
						for (var i = 0; i < array.length; i++) {
							alert(e);
							// 创建子元素
							var tr = $("<tr>");
							var str = array[i];

							var s = str.split(",");
							for (var j = 0; j < s.length; j++) {
								var td = $("<td>");
								td.text(s[j]);
								td.css("width", "18%");
								tr.append(td);
							}
							if(s.length>2){
								var td1 = $("<td>");
								var input1 = $("<input />")
								input1.attr("type", "button");
								input1.val("删除");
								input1
										.addClass("btn btn-default del-a btn btn-danger shanchucaogao");
								td1.append(input1);

								var td2 = $("<td>");
								var input2 = $("<input />")
								input2.attr("type", "button");
								input2.val("发表");
								input2
										.addClass("btn btn-default del-a btn btn-danger fabiaocaogao");
								td1.append(input2);

								var td3 = $("<td>");
								var input3 = $("<input />")
								input3.attr("type", "button");
								input3.val("修改");
								input3
										.addClass("btn btn-default del-a btn btn-danger xiugaicaogao");
								td1.append(input3);

							}
							
							tr.append(td1);
							tr.addClass("myarticle1");
							table.append(tr);

						}
					}
				});
		 
	}
</script>
</head>
<body>
	<div id="" class="mright" style="width: 80%; height: 800px;">
		<div id="" class="r_head">
			<img src="../img/bianji.png" />&nbsp;日志管理
		</div>
		<div id="myTab">

			<!-- Nav tabs -->
			<ul class="nav nav-tabs" role="tablist">
				<li role="presentation" class="active"><a href="#home"
					aria-controls="home" role="tab" data-toggle="tab">日志</a></li>
				<li role="presentation"><a href="#profile"
					aria-controls="profile" role="tab" data-toggle="tab">写日志</a></li>

				<li role="presentation"><a href="#caogaoxiang"
					aria-controls="caogaoxiang" role="tab" data-toggle="tab">草稿箱</a></li>


			</ul>

			<!-- Tab panes -->
			<div class="tab-content">
				<!-- 日志 -->
				<div role="tabpanel" class="tab-pane fade in active " id="home">
					<form class="navbar-form navbar-left" method="get">
						<div class="form-group">
							<input type="text" name="text" class="form-control" id="text"
								placeholder="请输入文章编号或文章类型">
						</div>
						<button type="button" class="btn btn-default" onclick="chaxun()">查询</button>
					</form>

					<table class="table table-striped table-hover table-bordered">
						<tr class="info">
							<th>文章编号</th>
							<th>文章标题</th>
							<th>文章类型</th>
							<th>发布时间</th>
							<th>操作</th>
						</tr>
					</table>
					<table class="table table-striped table-hover table-bordered add"
						id="table">
						<c:forEach items="${art}" var="al">
							<tr class="myarticle">
								<td>${al.artId }</td>
								<td>${al.title }</td>
								<td>${al.artClass }</td>
								<td>${al.artTime }</td>
								<td><a
									class="btn btn-default del-a btn btn-danger shanchuart"
									href="#" role="button">删除</a> <a
									class="btn btn-default del-a btn btn-danger xiugaiart" href="#"
									role="button" id="xiugaiart">修改</a></td>
								<!-- data-toggle="modal" data-target="#myModal" -->

							</tr>
						</c:forEach>
						<input type="hidden" name="shanchuaId" id="shanchuaId" value="" />
					</table>

					<!-- 模态 -->
					<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
						aria-labelledby="myModalLabel">
						<div class="modal-dialog" role="document">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal"
										aria-label="Close">
										<span aria-hidden="true">&times;</span>
									</button>
									<h4 class="modal-title" id="myModalLabel">修改文章信息</h4>
								</div>
								<div class="modal-body xugai">
									<form action="rizhigl" method="post" id="artFrom">
										<div class="row">
											文章编号：<input type="text" id="artId" value=""
												disabled="disabled" /><input type="hidden" name="xgartId"
												id="xgartId" />
										</div>
										<div class="row">
											文章标题：<input type="text" name="xgartTitle" id="xgartTitle"
												value="" />
										</div>
										<div class="row">
											文章类型： <select name="xfartclassId" id="xfartclassId">
												<c:forEach items="${cla }" var="clas">
													<option value="${clas.classId }">${clas.className }</option>
												</c:forEach>

											</select>
										</div>
										<div class="row">
											发表时间：<input type="text" name="xgartTime" id="xgartTime"
												value="" disabled="disabled" />
										</div>
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default"
										data-dismiss="modal">取消</button>
									<button type="submit" class="btn btn-primary">确定</button>

								</div>
								</form>
							</div>
						</div>
					</div>
				</div>





				<!-- 写日志 -->
				<div role="tabpanel" class="tab-pane fade  " id="profile">
					<form action="rizhigl" method="post" id="artFrom"
						onsubmit="return artFrom()">
						<div class="writeArticle">
							选择分类：<select name="classId">
								<c:forEach items="${cla }" var="clas">
									<option value="${clas.classId }">${clas.className }</option>
								</c:forEach>

							</select>
						</div>
						<div class="writeArticle">
							文章标题：<input type="text" name="title" id="title"
								placeholder="请输入文章标题" /> <label id="titleLabel"></label>
						</div>

						<div class="writeArticle">
							<div class="row  ">
								<textarea id="editor" name="artText" placeholder="请输入文章内容"
									autofocus></textarea>
								<label id="editorLabel"></label>
								<script>
									var editor = new Simditor({
										textarea : $('#editor')
									//optional options
									});
								</script>
							</div>
						</div>
						<div class="writeArticle">
							<input type="submit" id="fabiao" name="fabiao" value="发表"
								onclick="sub('fabiao')" /> <input type="submit" id="caogao"
								name="caogao" value="存草稿" onclick="sub('caogao')" /> <input
								type="hidden" name="statement" id="statement" value="" />
						</div>
					</form>

				</div>

				<!-- 草稿箱 -->
				<div role="tabpanel" class="tab-pane fade " id="caogaoxiang">


					<table class="table table-striped table-hover table-bordered">
						<tr class="info">
							<th>文章编号</th>
							<th>文章标题</th>
							<th>文章类型</th>
							<th>发布时间</th>
							<th>操作</th>
						</tr>
					</table>
					<table class="table table-striped table-hover table-bordered add1"
						id="caogaotable">
						<c:forEach items="${art1}" var="al">
							<tr class="myarticle2">
								<td>${al.artId }</td>
								<td>${al.title }</td>
								<td>${al.artClass }</td>
								<td>${al.artTime }</td>
								<td><a
									class="btn btn-default del-a btn btn-danger shanchucaogao"
									href="#" role="button">删除</a> <a
									class="btn btn-default del-a btn btn-danger xiugaicaogao"
									href="#" role="button" id="xiugaicaogao">修改</a><a
									class="btn btn-default del-a btn btn-danger fabiaocaogao"
									href="#" role="button">发表</a></td>


							</tr>
							
						</c:forEach>
						<input type="hidden" id="caogaostate" name="caogaostate" / >
						<input type="hidden" name="caogaoId" id="caogaoId" value="" />
					</table>

					<!-- 模态 -->
					<div class="modal fade" id="myModal1" tabindex="-1" role="dialog"
						aria-labelledby="myModalLabel">
						<div class="modal-dialog" role="document">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal"
										aria-label="Close">
										<span aria-hidden="true">&times;</span>
									</button>
									<h4 class="modal-title" id="myModalLabel">修改文章信息</h4>
								</div>
								<div class="modal-body xugai">
									<form action="rizhigl" method="post" id="artFrom">
										<div class="row">
											文章编号：<input type="text" id="caogaoartId" value=""
												disabled="disabled" /><input type="hidden"
												name="caogaoxgartId" id="caogaoxgartId" />
										</div>
										<div class="row">
											文章标题：<input type="text" name="caogaoxgartTitle"
												id="caogaoxgartTitle" value="" />
										</div>
										<div class="row">
											文章类型： <select name="caogaoxfartclassId"
												id="caogaoxfartclassId">
												<c:forEach items="${cla }" var="clas">
													<option value="${clas.classId }">${clas.className }</option>
												</c:forEach>

											</select>
										</div>
										<div class="row">
											发表时间：<input type="text" name="caogaoxgartTime"
												id="caogaoxgartTime" value="" disabled="disabled" />
										</div>
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default"
										data-dismiss="modal">取消</button>
									<button type="submit" class="btn btn-primary">确定</button>

								</div>
								</form>
							</div>
						</div>
					</div>



				</div>
			</div>

		</div>

	</div>
</body>
</html>